package com.xnfh.field.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.xnfh.common.bean.TendencyYearBean
import com.xnfh.common.bean.UavImgBean
import com.xnfh.field.R
import com.xnfh.field.databinding.AdapterTendencyDateBinding

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/12/6 17:23
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/12/6 17:23
 * @UpdateRemark: 更新说明
 */
class TendencyMonthAdapter :
    BaseQuickAdapter<UavImgBean, BaseDataBindingHolder<AdapterTendencyDateBinding>>(R.layout.adapter_tendency_date) {
    private var listener: onItemSelectMonth? = null
    private var currSelect = 0
    override fun convert(holder: BaseDataBindingHolder<AdapterTendencyDateBinding>, item: UavImgBean) {
        val dataBinding = holder.dataBinding
        holder.setText(R.id.item_tendency_date,item.date)
        dataBinding?.itemTendencyDate?.setOnClickListener {
            if(currSelect != holder.layoutPosition){
                //取消上次选中的
                data[currSelect].selected = false
                notifyItemChanged(currSelect)
                //刷新当前选中的
                currSelect = holder.layoutPosition
                data[currSelect].selected = true
                notifyItemChanged(currSelect)
                //回调给activity
                listener?.setSelect(currSelect)
            }
        }

    }

    interface onItemSelectMonth {
        fun setSelect(position: Int)
    }

    fun setOnItemSelectMonthistener(listener: onItemSelectMonth) {
        this.listener = listener
    }
}